﻿// Write a program that finds the maximal sequence of equal elements in an array.

using System;

class FindMaxEqualElementSequence
{
    static void Main()
    {
        Console.Write("Enter array lenght: ");
        int arraySize = int.Parse(Console.ReadLine());

        string[] stringArray = new string[arraySize];
        for (int i = 0; i < stringArray.Length; i++)
        {
            Console.Write("Enter element {0} from array: ", i + 1);
            stringArray[i] = Console.ReadLine();
        }

        string element = null;
        int maxEqualNumbersCount = 0;
        int equalNumbersCount = 1;
        bool equalSequence = false;
        if (stringArray.Length != 1)
        {
            for (int i = 1; i < stringArray.Length; i++)
            {
                if (stringArray[i - 1] == stringArray[i])
                {
                    equalNumbersCount++;
                    if (equalNumbersCount > maxEqualNumbersCount)
                    {
                        maxEqualNumbersCount = equalNumbersCount;
                        element = stringArray[i];
                        equalSequence = false;
                    }
                    else if (equalNumbersCount == maxEqualNumbersCount)
                    {
                        // if more than one equal sequence
                        equalSequence = true;
                    }
                }
                else
                {
                    equalNumbersCount = 1;
                }
            }
        }
        else
        {
            element = stringArray[0];
            maxEqualNumbersCount = 1;
            equalNumbersCount = 0;
        }

        if (maxEqualNumbersCount > 1 && !equalSequence)
        {
            Console.Write("The maximal sequence of equal elements is: {");
            for (int i = 0; i < maxEqualNumbersCount; i++)
            {
                Console.Write(element);
                if (i < maxEqualNumbersCount - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine("}");
        }
        else
        {
            Console.WriteLine("Sequence of equal element not exist");
        }
    }
}